package org.shan.lis;


import com.alibaba.fastjson.JSON;
import org.shan.lis.common.model.PersonResult;
import org.shan.lis.net.SerialMqClient;
import org.shan.lis.shy.ShySerial;

import java.io.IOException;
import java.util.List;

/**
 * Created by amanda.shan on 2019/8/29.
 */
public class DeviceController {

    public static void main(String[] args) throws IOException {

        String shyPort = args[0];
        String netPort = args[1];

        System.out.println("shy: "+shyPort);
        System.out.println("net: "+netPort);

        ShySerial shySerial = new ShySerial(shyPort);
        shySerial.openSerialPort();

        SerialMqClient serialMqClient = new SerialMqClient(netPort);
        serialMqClient.openSerialPort();

        shySerial.setShyDataLis(new ShySerial.ShyDataLis() {
            @Override
            public void shyData(List<PersonResult> personResults) {

                try {
                    serialMqClient.push(JSON.toJSONString(personResults));

                    System.out.println("推送数据:"+JSON.toJSONString(personResults));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });

//        testSend();
    }

    private static void testSend() throws IOException {

        SerialMqClient serialMqClient = new SerialMqClient("COM4");
        serialMqClient.openSerialPort();

        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < 10; i++) {
            builder.append("a");
        }
//        serialMqClient.push(builder.toString());

        serialMqClient.ping();
    }
}
